import { CommentOwn } from '../common.js';

export const Comment = layer => Object.assign(
  CommentOwn(),
  { layerId: layer.id }
);

export function useComment(xs) {
  const findComment = layer => R.find(R.propEq(layer.id, 'layerId'), xs.value);

  function clear() {
    xs.value.splice(0);
  }

  function del(dataItem) {
    if (!xs.value.includes(dataItem)) { return; }
    xs.value.splice( xs.value.indexOf(dataItem), 1 );
  }

  return {
    clear,
    del,
    findComment,
  };
}
